package com.ny.controller;
import com.ny.pojo.ClassRoom;
import com.ny.pojo.User;
import com.ny.service.UserService;
import com.ny.service.impl.UserServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.sql.SQLException;
import java.util.List;

@Controller
public class UserController {
//
//    UserService userService = new UserServiceImpl();
    @Autowired
    private UserService userService;

//    接收到登录的信息:学号和密码
    @RequestMapping("/login")
    public String login(User user, Model model) throws SQLException, ClassNotFoundException {
//        如果登录成功，就查询所有的教室信息
//      获取到用户名和密码,把学号和密码交给谁？
        System.out.println(user);
        boolean flag =  userService.login(user.getUser_Id(), user.getPassword());
        if(flag){
//            登录成功显示教室的信息在jsp界面：调用service的查询所有教室的信息的方法
            List<ClassRoom>  classRoomList = userService.findAllRoom();
            model.addAttribute("classRoomList",classRoomList);
            return "classroom";
        }
            return "index";
    }
}
